﻿/// <summary>
///     获取当前登录会员的Session
/// </summary>
/// <returns>
///     null        当前用户未登录
///     MemberModel 当前登录用户对象
/// </returns>
function getSessionMember() {
    var req = new requestCommand(999);
    req.async = false;
    var member = null;
    req.get(function (data) { member = data; });
    return member;
}

function ajaxRequest(url) {
    this.async = true;
    this.url = url;
//    if (g_langID != null && typeof g_langID != "undefined") {
//        if (this.url.indexOf("?") > -1)
//            this.url += "&langID=" + g_langID;
//        else
//            this.url += "?langID=" + g_langID;
//    }
    this.dataType = 'json';
    this.get = function (success_callback) { return __get(this, success_callback); };
    this.post = function (postData, success_callback) { return __post(this, postData, success_callback); };

    function __get(request, success_callback) {
        jQuery.ajax({
            url: request.url,
            type: 'get',
            async: request.async,
            dataType: request.dataType,
            success: function (r) { return success_callback(r); }
        });
    }

    function __post(request, postData, success_callback) {
        jQuery.ajax({
            url: request.url,
            type: 'post',
            async: request.async,
            data: postData,
            dataType: request.dataType,
            success: function (r) { return success_callback(r); }
        });
    }
}

function requestCommand(cmd, cmdArgs) {
    this.command = cmd;
//    this.langID = 2052;
    this.async = true;

    this.url = "/xmlhttpgate.aspx?cmd=" + this.command + "&random=" + new Date().toLocaleString();
    if (cmdArgs != null && typeof cmdArgs != "undefined") {
        if (cmdArgs.length > 0) {
            if (cmdArgs.substring(0, 1) == "&")
                this.url += cmdArgs;
            else
                this.url += "&" + cmdArgs;
        }
    }

    this.request = new ajaxRequest(this.url);
    this.request.async = this.async;

    this.get = function (success_callback) { this.request.async = this.async; return this.request.get(success_callback); };
    this.post = function (postData, success_callback) { this.request.async = this.async; return this.request.post(postData, success_callback); };
}

//处理null链接的问题
function IsNull(obj) {
    return (!obj) ? "" : obj;
}
//var g_langID = 1033;
var globals = {};
//globals.option = g_langID == 2052 ? "请选择" : "select";
globals.header_def = "/uploadfiles/defaultImg/header_def.jpg";
globals.featured_def = "/uploadfiles/defaultImg/featured_def.jpg";
globals.hotspot_def = "/uploadfiles/defaultImg/hotspot_def.jpg";
globals.enevtimg_def = "/uploadfiles/defaultImg/events_list_def.jpg";
globals.logout_tip = "Do you confirm exit?";
//globals.CancelMembership = "Do you CancelMembership?";
//globals.notmapevent = "Please note the concept activity";
//globals.haseventset = "has set up";
//globals.canceleventmap = "Note the concept has been cancelled";
globals.myprofilesucc = "Modification of success";
//globals.mycomment = "Confirm delete comments";

//格式化json的时间 
function FormatTime(jsonDate) {
    jsonDate = jsonDate.split('(')[1].split(')')[0];
    var rDate = new Date(parseInt(jsonDate));
    return rDate.toLocaleDateString();
}
function renderTime(data) {
    if (data == null || typeof data == "undefined") return "";
    var date = new Date(parseInt(data.replace("/Date(", "").replace(")/", ""), 10));
    var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
    var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
    var s = currentDate + "/" + month + "/" + date.getFullYear();
    if (date.getHours() == 0 && date.getMinutes() == 0)
        return s;
    else
        return s + " " + date.getHours() + ":" + date.getMinutes();
}

function ChangeDateFormat(jsondate) {
    jsondate = jsondate.replace("/Date(", "").replace(")/", "");
    if (jsondate.indexOf("+") > 0) {
        jsondate = jsondate.substring(0, jsondate.indexOf("+"));
    }
    else if (jsondate.indexOf("-") > 0) {
        jsondate = jsondate.substring(0, jsondate.indexOf("-"));
    }

    var date = new Date(parseInt(jsondate, 10));
    var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
    var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
    return date.getFullYear() + "-" + month + "-" + currentDate;
}  